package com.waypolice.manager.service.impl;

import com.waypolice.common.constant.BorrowConstant;
import com.waypolice.common.constant.Constants;
import com.waypolice.manager.service.FirstHomeService;
import com.waypolice.mapper.CmsBorRegisterMapper;
import com.waypolice.mapper.CmsJudItemMapper;
import com.waypolice.mapper.CmsJudVolumeMapper;
import com.waypolice.mapper.CmsSinItemMapper;
import com.waypolice.pojo.CmsBorRegisterExample;
import com.waypolice.pojo.CmsJudItemExample;
import com.waypolice.pojo.CmsJudVolumeExample;
import com.waypolice.pojo.CmsSinItemExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description 主页面上半部分统计
 * @Author wangrang
 * @Date Created in 8:51 2019/4/24
 * @Modified By:
 */
@Service
public class FirstHomeServiceImpl implements FirstHomeService {

    @Autowired
    private CmsJudVolumeMapper cmsJudVolumeMapper;

    @Autowired
    private CmsJudItemMapper cmsJudItemMapper;

    @Autowired
    private CmsSinItemMapper cmsSinItemMapper;

    @Autowired
    private CmsBorRegisterMapper cmsBorRegisterMapper;

    @Override
    public Map<String, String> homePageAllCountData() {
        Map<String, String> countData = new HashMap<>();
        //总卷数
        CmsJudVolumeExample cmsJudVolumeExample = new CmsJudVolumeExample();
        CmsJudVolumeExample.Criteria criteria = cmsJudVolumeExample.createCriteria();
        int volData = cmsJudVolumeMapper.countByExample(cmsJudVolumeExample);
        String string = formatString(Float.valueOf(volData));
        countData.put("allVolCountData",string);
        //卷内件数
        CmsJudItemExample cmsJudItemExample = new CmsJudItemExample();
        int itemData = cmsJudItemMapper.countByExample(cmsJudItemExample);
        String string1 = formatString(Float.valueOf(itemData));
        countData.put("allItemCountData",string1);
        //单件数
        CmsSinItemExample cmsSinItemExample = new CmsSinItemExample();
        int singleItemData = cmsSinItemMapper.countByExample(cmsSinItemExample);
        String string2 = formatString(Float.valueOf(singleItemData));
        countData.put("allSinItemCountData",string2);
        //卷归档数
        CmsJudVolumeExample cmsJudVolumeExampleArchive = new CmsJudVolumeExample();
        CmsJudVolumeExample.Criteria criteriaArchVol = cmsJudVolumeExampleArchive.createCriteria();
        criteriaArchVol.andVolArchiveStatusEqualTo(2);
        int volDataArchive = cmsJudVolumeMapper.countByExample(cmsJudVolumeExampleArchive);
        String string3 = formatString(Float.valueOf(volDataArchive));
        countData.put("allVolCoutDataArc",string3);
        //单件归档数
        CmsSinItemExample cmsSinItemExampleArchive = new CmsSinItemExample();
        CmsSinItemExample.Criteria criteriaArchSinItem = cmsSinItemExampleArchive.createCriteria();
        criteriaArchSinItem.andItemArcStatusEqualTo(1L);
        int singleItemDataArchive = cmsSinItemMapper.countByExample(cmsSinItemExampleArchive);
        String string4 = formatString(Float.valueOf(singleItemDataArchive));
        countData.put("allSinItemCountDataArc",string4);
        //借阅数  //查借阅登记中 借阅申请通过的的数据
        CmsBorRegisterExample cmsBorRegisterExample = new CmsBorRegisterExample();
        CmsBorRegisterExample.Criteria cmsBorRegisterExampleCriteria = cmsBorRegisterExample.createCriteria();
        cmsBorRegisterExampleCriteria.andExtend2EqualTo("1");
        List<Integer> list = new ArrayList<>();
        list.add(BorrowConstant.AUDIT_TYPE_BORROW);
        list.add(BorrowConstant.AUDIT_TYPE_RENEW);
        cmsBorRegisterExampleCriteria.andTaskTypeIn(list);
        int borrowNum = cmsBorRegisterMapper.countByExample(cmsBorRegisterExample);
        countData.put("allBorrowCountData",String.valueOf(borrowNum));
        return countData;
    }


    public static String formatString(float data) {
        DecimalFormat df = new DecimalFormat("#,###");
        return df.format(data);
    }
    public static void main(String[] args) {
        System.out.println(formatString(0));
    }

}
